
import 'package:ycbl/model/TestModel.dart';
import 'package:ycbl/model/bl_error_entity.dart';
import 'package:ycbl/net/http/bl_request_manager.dart';
import 'package:ycbl/utils/log_util.dart';
import 'package:ycbl/widget/provider/base_view_state_list_model.dart';

class TestViewModel extends BaseViewStateListModel<TestData> {
  @override
  internalLoadData({int startIndex, Function(List<TestData> p1) onListSuccess, Function(BLErrorEntity p1) onListError}) {

    //按照分层 网络请求应该写在 repository 中，这里测试就不放了
    BLRequestManager.getInstance().get('https://wanandroid.com/wxarticle/chapters/json', onSuccess: (data){
      var model = TestModel.fromJson(data);
      if(model?.data != null) {
        onListSuccess(model.data);
      }else {
        onListError(BLErrorEntity(message: '加载数据失败'));
      }
    }, onError: onListError);

  }

  @override
  onLoadComplete(List<TestData> newListData) {
    LogUtil.d('onLoadComplete');
    return super.onLoadComplete(newListData);
  }


}